package com.accesshollywood.indexables;

import java.util.Iterator;
import java.util.LinkedHashMap;

import com.accesshollywood.components.EditableListWithPopup.EditableListModel;

public abstract class AbstractIndexedMap<U, T extends Indexed> extends Indexed {
	protected LinkedHashMap<U, T>	map	= new LinkedHashMap<U, T>();

	public AbstractIndexedMap() {
		super();
		initSQL();
	}

	public boolean isEmpty() {
		return map.isEmpty();
	}

	public Iterator iterator() {
		return map.values().iterator();
	}

	public int size() {
		return map.size();
	}

	public void clear() {
		map.clear();
	}
	
	public void put(U key, T obj){
		map.put(key, obj);
	}
	
	public void remove(int index){
		map.remove(index);
	}
	
	public T get(int index){
		Iterator itr = iterator();
		int i = 0;
		while(itr.hasNext()){
			T curr = (T) itr.next();
			if(i++ == index){
				return curr;
			}
		}
		return null;
	}

	public EditableListModel toEditableListModel() {
		EditableListModel model = new EditableListModel();
		Iterator itr = iterator();
		int i = 0;
		while (itr.hasNext()) {
			Indexed curr = (Indexed) itr.next();
			model.addElement(curr);
		}
		return model;
	}

}
